{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 🎯 Setting up CSPOT \n",
    "\n",
    "### Kindly note that **CSPOT is not a plug-and-play solution**, rather it's a framework that requires significant upfront investment of time from potential users for training and validating deep learning models, which can then be utilized in a plug-and-play manner for processing large volumes of similar multiplexed imaging data.\n",
    "\n",
    "**There are two ways to set it up based on how you would like to run the program**\n",
    "- Using an interactive environment like Jupyter Notebooks\n",
    "- Using Command Line Interface"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Before we set up CSPOT, we highly recommend using a environment manager like Conda. Using an environment manager like Conda allows you to create and manage isolated environments with specific package versions and dependencies. \n",
    "\n",
    "**Download and Install the right [conda](https://docs.conda.io/en/latest/miniconda.html) based on the opertating system that you are using**\n",
    "\n",
    "We have tested the following \n",
    "- Linux (CPU, GPU)\n",
    "- Windows (CPU, GPU)\n",
    "- Windows WSL (CPU, GPU)\n",
    "- Mac: Intel (CPU)\n",
    "- Mac M1 or M2 (CPU)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Let's create a new conda environment and install CSPOT\n",
    "\n",
    "use the terminal (mac/linux) and anaconda promt (windows) to run the following command\n",
    "```\n",
    "conda create --name cspot -y python=3.9\n",
    "```\n",
    "\n",
    "**Install `CSPOT` within the conda environment.**\n",
    "\n",
    "```\n",
    "conda activate cspot\n",
    "pip install cspot\n",
    "```\n",
    "\n",
    "## If you would like CSPOT to use GPU:\n",
    "cspot uses Tensorflow. Please install necessary packages for tensorflow to recogonise your specific GPU.  \n",
    "We have tested the following command in windows machine using nvidia GPU. Does not work on windows WSL2 due to tensorflow's dependency issues.\n",
    "\n",
    "```\n",
    "conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0 -y \n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Download the Exemplar Dataset\n",
    "To help you get used to the program we have provided some dummy data.   \n",
    "**Download link to the [exemplar dataset provided here.](https://doi.org/10.7910/DVN/C45JWT)**  \n",
    "All of the following files are mandatory for running cspot, but `phenotype_workflow.csv` is optional and can be skipped if single cell phenotyping is not required. `manuscriptModels` is provided explicitly for going through this tutorial. \n",
    "```\n",
    "cspotExampleData/\n",
    "├── image\n",
    "│   └── exampleImage.tif\n",
    "├── manuscriptModels\n",
    "│   ├── CD3D\n",
    "│   ├── CD4\n",
    "│   ├── CD45\n",
    "│   ├── CD8A\n",
    "│   ├── ECAD\n",
    "│   └── KI67\n",
    "├── markers.csv\n",
    "├── phenotype_workflow.csv\n",
    "├── quantification\n",
    "│   └── exampleSpatialTable.csv\n",
    "└── segmentation\n",
    "    └── exampleSegmentationMask.tif\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Method 1: Set up Jupyter Notebook (If you would like to run CSPOT in an interactive setting)\n",
    "Install jupyter notebook within the conda environment\n",
    "```\n",
    "conda activate cspot\n",
    "pip install notebook\n",
    "```\n",
    "After installation, open Jupyter Notebook by typing the following command in the terminal, ensuring that the cspot environment is activated and you are within the environment before executing the jupyter notebook command.\n",
    "```\n",
    "jupyter notebook\n",
    "```\n",
    "We will talk about how to run cspot in the next tutorial."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Method 2: Set up Command Line Interface (If you like to run CSPOT in the CLI, HPC, etc)\n",
    "\n",
    "Activate the conda environment that you created earlier\n",
    "\n",
    "```\n",
    "conda activate cspot\n",
    "```\n",
    "\n",
    "**MAC / LINUX / WSL**  \n",
    "If you have git installed you can clone the repo with the following command\n",
    "```\n",
    "git clone https://github.com/nirmallab/cspot\n",
    "cd cspot/cspot/\n",
    "```\n",
    "\n",
    "*OR*  \n",
    "\n",
    "```\n",
    "wget https://github.com/nirmalLab/cspot/archive/main.zip\n",
    "unzip main.zip \n",
    "cd cspot-main/cspot \n",
    "```\n",
    "\n",
    "**WINDOWS**  \n",
    "If you have git installed you can pull the repo with the following command\n",
    "```\n",
    "git clone https://github.com/nirmallab/cspot\n",
    "```\n",
    "\n",
    "*OR*  \n",
    "  \n",
    "Head over to https://github.com/nirmallab/cspot in your browser and download the repo.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Method 3: Set up Docker\n",
    "\n",
    "Follow the docker installation guide to install docker: https://docs.docker.com/engine/install/\n",
    "\n",
    "**Download CSPOT from Docker Hub**\n",
    "```\n",
    "docker pull nirmallab/cspot:latest\n",
    "```\n",
    "\n",
    "There is a special tutorial on how to run cspot with docker, please refer to that for further instructions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  },
  "vscode": {
   "interpreter": {
    "hash": "4d975fac4fcc437c670ab44b5da89fd54fa784afb4bff9f75c9477844a77bbbe"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
